//
//  WMHttpTool.h
//  WMHttpTool
//
//  Created by 郑想 on 15/10/12.
//  Copyright (c) 2015年 wmzheng. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, WMNetworkType) {
    WMNetworkTypeNoNetwork = -1,
    WMNetworkTypeWWAN = 0,
    WMNetworkTypeWiFi = 1,
};

@protocol WMHttpToolDelegete <NSObject>
- (void)reachabilityStatusChange:(BOOL)existNetwork;
@end

@interface WMHttpTool : NSObject
@property (nonatomic, copy) NSDictionary* HTTPHeaders;
//defaulte YES:Show
@property (nonatomic, assign) BOOL showNetworkIndicator;
@property (nonatomic, assign) WMNetworkType networkType;
@property (nonatomic, weak) id<WMHttpToolDelegete> delegate;
+ (instancetype)shareHttpTool;

/**
 *  发送get请求
 *
 *  @param url     请求地址
 *  @param params  参数
 *  @param success 成功调用代码块
 *  @param failure 失败调用代码块
 *
 *  @return NSOperation
 */
- (NSOperation*)getWithUrl:(NSString*)url params:(NSDictionary*)params success:(void (^)(NSHTTPURLResponse* response, id json))success failure:(void (^)(NSHTTPURLResponse* response, NSError* error))failure;

/**
 *  发送post请求
 *
 *  @param url     请求地址
 *  @param params  参数
 *  @param success 成功调用代码块
 *  @param failure 失败调用代码块
 *
 *  @return NSOperation
 */
- (NSOperation*)postWithUrl:(NSString*)url params:(NSDictionary*)params success:(void (^)(NSHTTPURLResponse* response, id json))success failure:(void (^)(NSHTTPURLResponse* response, NSError* error))failure;

/**
 *  发送put请求
 *
 *  @param url     请求地址
 *  @param params  参数
 *  @param success 成功调用代码块
 *  @param failure 失败调用代码块
 *
 *  @return NSOperation
 */
- (NSOperation*)putWithUrl:(NSString*)url params:(NSDictionary*)params success:(void (^)(NSHTTPURLResponse* response, id json))success failure:(void (^)(NSHTTPURLResponse* response, NSError* error))failure;

/**
 *  发送delete请求
 *
 *  @param url     请求地址
 *  @param params  参数
 *  @param success 成功调用代码块
 *  @param failure 失败调用代码块
 *
 *  @return NSOperation 可调用cancel取消网络请求
 */
- (NSOperation*)deleteWithUrl:(NSString*)url params:(NSDictionary*)params success:(void (^)(NSHTTPURLResponse* response, id json))success failure:(void (^)(NSHTTPURLResponse* response, NSError* error))failure;

/**
 *  下载文件
 *
 *  @param downloadUrl 下载url
 *  @param savePath    保存文件路径
 *  @param progress    进度获取
 *  @param completion  下载结束调用代码块
 */

- (void)downloadFileWithUrl:(NSString*)downloadUrl toPath:(NSString*)savePath progress:(void (^)(float progress))progressBlock completion:(void (^)(NSURLResponse* response, NSURL* filePath, NSError* error))completionBlock;

/**
 *  开始监控网络变化
 */
- (void)startMonitoring;

/**
 *  停止监控网络变化
 */
- (void)stopMonitoring;

/**
 *  获取网络连接状态
 *
 *  @return YES 连接
 */
- (BOOL)existenceNetwork;

/**
 *  取消所有的网络请求
 */
- (void)cancelAllRequest;
@end
